#!/usr/bin/env bash

set -euxo pipefail

BRANCH=$1
REMOTE=$2
CHAIN=$3
DOMAIN=$4

if [[ ! -d $REMOTE ]]; then
  mkdir -p $REMOTE
  git clone https://github.com/$REMOTE.git $REMOTE
fi

cd $REMOTE

git fetch origin
git checkout -B $BRANCH
git reset --hard origin/$BRANCH

COMMIT=$(git rev-parse --short HEAD)

./deploy/setup $CHAIN $DOMAIN $BRANCH $COMMIT
